package org.jseda;

import org.jseda.queue.Queue;
import org.jseda.thread.ManagedThread;

/**
 * QueueConsumer pulls work units from a Queue and delegates them to a
 * Processor.
 * 
 * @author jmcnair
 */
public class QueueConsumer<T, V> implements ManagedThread
{
	private Queue<T> queue;
	private Processor<T, V> processor;
	private Publisher<V> publisher;

	/**
	 * @param queue
	 * @param processor
	 * @param publisher
	 */
	public QueueConsumer(Queue<T> queue, Processor<T, V> processor, Publisher<V> publisher)
	{
		this.queue = queue;
		this.processor = processor;
		this.publisher = publisher;
	}

	public void run()
	{
		// TODO Auto-generated method stub

	}

	public void cancel()
	{
		// TODO Auto-generated method stub

	}

	public boolean isRunning()
	{
		// TODO Auto-generated method stub
		return false;
	}

	public void executeLoopBody()
	{
		T workUnit = queue.popFront();
		if (null != workUnit)
			processor.processWork(workUnit, publisher);
	}

	public void setQueue(Queue<T> queue)
	{
		this.queue = queue;
	}

	public void setProcessor(Processor<T, V> processor)
	{
		this.processor = processor;
	}

	public void setPublisher(Publisher<V> publisher)
	{
		this.publisher = publisher;
	}
}
